package com.example.demo.controller;

import com.example.demo.common.AppResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


@Api(tags = "测试接口") //这个类中就全是测试接口
//指定测试根路径映射地址前缀
@RequestMapping("/test")
//Controller注解，返回的对象用JSON形式表示
@RestController
public class TestController {

    //127.0.0.1:58080/test/hello

    @ApiOperation("测试打印")
    @GetMapping("/hello")
    public String hello(){
        return "Hello";
    }

    //测试异常的接口
    @ApiOperation("测试异常")
    @GetMapping("/exception")
    public AppResult testException() throws Exception{
        throw new Exception("这是一个Exception...");
    }

    @ApiOperation("测试自定义异常")
    @GetMapping("/applicationException")
    public AppResult testApplicationException() throws Exception{
        throw new Exception("这是一个ApplicationException...");
    }

    @ApiOperation("测试传参")
    @GetMapping({"/helloByName"})
    public String testHelloByName(@ApiParam("名字") String name){
        return "hello," + name;
    }
}
